package com.linkoog.devtools.http.request.http_request.request_body.body.text;

import com.intellij.openapi.project.Project;
import com.linkoog.devtools.http.request.common.request_body.text.JsonRequestBody;
import com.linkoog.devtools.http.request.http_request.request_body.BodyPanel;
import com.linkoog.devtools.intellij.editor.JSONEditerPanel;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class JSONBodyPanel extends JSONEditerPanel implements BodyPanel<JsonRequestBody> {

    public JSONBodyPanel(@NotNull Project project) {
        super(project, "{\n}");
    }

    @Override
    public void resetRequestBody(@NotNull JsonRequestBody requestBody) {
        setEditorText(requestBody.getValue());
    }

    @Override
    public @NotNull JsonRequestBody buildRequestBody() {
        return JsonRequestBody.of(getEditorText());
    }

    @Override
    public JPanel getPanel() {
        return this;
    }
}
